
export interface Action<T = any> {
    type: T
}

/**
 * An Action type which accepts any other properties.
 * This is mainly for the use of the `Reducer` type.
 * This is not part of `Action` itself to prevent types that extend `Action` from
 * having an index signature.
 */
export interface AnyAction extends Action {
    // Allows any extra properties to be defined in an action.
    [extraProps: string]: any
}

interface Data {
    [prop: string]: any;
}

export interface ActionData extends AnyAction {
    data: Data
}
export class Message {
    public type:string;
    public data:ArrayBuffer;
    public static readonly ADD_BUFFER = 'ADD_BUFFER'
    public static readonly WRITE_BUFFER = 'WRITE_BUFFER'
    public static readonly INIT_ENCODER = 'INIT_ENCODER'
    public static readonly STOP_ENCODER = 'STOP_ENCODER'
    public static readonly SEND_FRAME_TO_ENCODER = 'SEND_FRAME_TO_ENCODER'
    public static readonly SEND_SURFCEID = 'SEND_SURFCEID'
    public static readonly SEND_IMAGE_CONFIG = 'SEND_IMAGE_CONFIG'
    public static readonly READ_YUV_FILE = 'READ_YUV_FILE'
    public Message(type:string,data:ArrayBuffer){
        this.type = type;
        this.data = data;
    }


    public static initWriteBufferMsg(buffer: ArrayBuffer): Message {
        let msg =  new Message();
        msg.type = Message.WRITE_BUFFER;
        msg.data = buffer;
        return msg
    }
    public static initInitEncoderMsg(): Message {
        let msg =  new Message();
        msg.type = Message.INIT_ENCODER;
        return msg
    }
    public static initStopEncoderMsg(): Message {
        let msg =  new Message();
        msg.type = Message.STOP_ENCODER;
        return msg
    }
    public static initSendDataMsg(buffer:SharedArrayBuffer) {
        let msg =  new Message();
        msg.type = Message.SEND_FRAME_TO_ENCODER;
        msg.data = buffer;
        return msg
    }
    public static initSurfaceIdMsg(surfaceId:string){
        return {
            type:Message.SEND_SURFCEID,
            data:surfaceId
        }
    }
    public static initImageConfigMsg(width:number,height:number,format:number){
        return {
            type:Message.SEND_IMAGE_CONFIG,
            width:width,
            height:height,
            format:format
        }
    }
    public static initReadYuvFileMsg(){
        return {
            type:Message.READ_YUV_FILE,
        }
    }
}